import { dasHttp, bizHttp } from '@/utils/request';
import type { PagePayload, DeepPartial, IResPageList, IRes, IResList } from '@/utils/request';

export interface IReleaseListParams {
	archiveTypeId?: number;
	businessType?: number;
	dataSource?: number;
	endTime?: string;
	fondsId?: number;
	name?: string;
	openHierarchy?: string;
	recordNo?: string;
	releaseEntryInfoJson?: string;
	releaseInfoJson?: string;
	releaseOriginalRuleJson?: string;
	releaseToNetwork?: number;
	releaseType?: number;
	remark?: string;
	startTime?: string;
	status?: number;
	templateId?: number;
}
export function fetchReleaseListByPage(data: PagePayload<IReleaseListParams>) {
	return dasHttp.post({
		url: '/archive-release-record/page',
		data
	});
}

export const dataSource = [
	{
		id: 1,
		name: '测试数据001',
		origin: '开发部',
		taskType: 2,
		status: 1,
		createdTime: '2022-01-23'
	},
	{
		id: 2,
		name: '测试数据002',
		origin: '测试部',
		taskType: 0,
		status: 2,
		createdTime: '2022-01-23'
	},
	{
		id: 3,
		name: '测试数据003',
		origin: '市场部',
		taskType: 1,
		status: 5,
		createdTime: '2022-01-23'
	},
	{
		id: 4,
		name: '测试数据004',
		origin: '开发部',
		taskType: 3,
		status: 7,
		createdTime: '2022-01-23'
	},
	{
		id: 5,
		name: '测试数据005',
		origin: '开发部',
		taskType: 3,
		status: 0,
		createdTime: '2022-01-23'
	},
	{
		id: 6,
		name: '测试数据006',
		origin: '开发部',
		taskType: 2,
		status: 5,
		createdTime: '2022-01-23'
	},
	{
		id: 7,
		name: '测试数据007',
		origin: '市场部',
		taskType: 2,
		status: 3,
		createdTime: '2022-01-23'
	},
	{
		id: 8,
		name: '测试数据008',
		origin: '开发部',
		taskType: 0,
		status: 2,
		createdTime: '2022-01-23'
	},
	{
		id: 9,
		name: '测试数据009',
		origin: '开发部',
		taskType: 0,
		status: 3,
		createdTime: '2022-01-23'
	},
	{
		id: 10,
		name: '测试数据010',
		origin: '测试部',
		taskType: 0,
		status: 1,
		createdTime: '2022-01-23'
	},
	{
		id: 11,
		name: '测试数据011',
		origin: '开发部',
		taskType: 2,
		status: 6,
		createdTime: '2022-01-23'
	},
	{
		id: 12,
		name: '测试数据012',
		origin: '测试部',
		taskType: 1,
		status: 5,
		createdTime: '2022-01-23'
	}
];

// 分页查询鉴定任务
export type TaskPageParam = DeepPartial<{
	endTime: string;
	goal: string;
	ids: any[];
	name: string;
	startTime: string;
	status: number;
	taskType: number;
	dataSource: number;
}>;

export type TaskPageItem = {
	appraisalLink: string;
	archiveCount: number;
	createOperator: string;
	createOperatorName: string;
	createdTime: string;
	goal: string;
	id: number;
	isSkipAudit: number;
	name: string;
	releaseTime: string;
	status: number;
	taskType: number;
};

export type ListItemRes = (typeof dataSource)[number];

export function selectTaskPage(data: PagePayload<TaskPageParam>) {
	// return bizHttp.post<IResPageList<TaskPageItem>>({
	// 	url: '/appraisal-task/page',
	// 	data
	// });
	return new Promise<IResPageList<ListItemRes>>((resolve) => {
		setTimeout(() => {
			const { pageNo, pageSize } = data;
			const index = (pageNo - 1) * pageSize;
			resolve({
				code: 200,
				message: 'success',
				data: {
					results: dataSource.slice(index, index + pageSize),
					totalCount: dataSource.length,
					pageNo,
					pageCount: pageNo,
					pageSize
				}
			});
		}, 500);
	});
}
export function selectList() {
	return new Promise<IResList<(typeof dataSource)[number]>>((resolve) => {
		setTimeout(() => {
			resolve({
				code: 200,
				message: 'success',
				data: dataSource
			});
		}, 500);
	});
}

export const selectTestForm = (data: { title: string }, type: string) =>
	new Promise<IRes<{ title: string }>>((resolve, reject) => {
		if (data.title === '123') {
			setTimeout(() => {
				resolve({ code: 200, data: { title: '牛逼，成功了' }, message: 'success' });
			}, 2000);
		} else {
			reject({ code: 500, data: { title: '垃圾，传错了' }, message: 'error' });
		}
	});
